/**
 * Copyright(c): 2018 com.mjduan All rights reserved.
 * 项目名：learn-spring-web
 * 注意：未经作者允许，不得外传
 */
package com.mjduan.project.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author dmj1161859184@126.com 2018-09-02 22:44
 * @version 1.0
 * @since 1.0
 */
@Controller
public class SpringSessionController {

    @RequestMapping(value = "/springsession")
    @ResponseBody
    public MySpringSessionModel getMySpringSessionModel(HttpServletRequest request){
        System.out.println("springsession收到请求");
        HttpSession session = request.getSession();
        String username = request.getParameter("username");
        if (null != username && username.length() > 0) {
            session.setAttribute("username", username);
        }
        return new MySpringSessionModel(username,username+" value");
    }

    private static class MySpringSessionModel{
        private String name;
        private String value;

        public MySpringSessionModel(String name, String value) {
            this.name = name;
            this.value = value;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }
}
